package com.cityeye.util;

public class Page {
	public static int DEF_ROWS_PER_PAGE = 8;

	private int curPage = 1;

	private int maxPage;

	private int maxRowCount;

	private int rowsPerPage = DEF_ROWS_PER_PAGE;

	public Page() {
	}

	public Page(int rowCount, int rows1Page) {
		maxRowCount = rowCount;
		this.rowsPerPage = rows1Page;
		if (this.maxRowCount % this.rowsPerPage == 0) {
			this.maxPage = this.maxRowCount / this.rowsPerPage;
		} else {
			this.maxPage = this.maxRowCount / this.rowsPerPage + 1;
		}
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int page) {
		if (page < 1) {
			page = 1;
		} else if (page > maxPage) {
			page = maxPage;
		}
		this.curPage = page;
	}

	public int getMaxPage() {
		return maxPage;
	}

	public void setMaxPage(int maxPage) {
		this.maxPage = maxPage;
	}

	public int getMaxRowCount() {
		return maxRowCount;
	}

	public void setMaxRowCount(int maxRowCount) {
		this.maxRowCount = maxRowCount;
	}

	public int getRowsPerPage() {
		return rowsPerPage;
	}

	public void setRowsPerPage(int rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}

	public void first() {
		curPage = 1;
	}

	public void previous() {
		if (curPage > 1)
			curPage--;
		else
			curPage = 1;
	}

	public void next() {
		if (curPage < maxPage)
			curPage++;
	}

	public void last() {
		curPage = maxPage;
	}
}